#include "node.h"

node::node(int nb, char *st, double xx, double yy):mcoord(xx, yy),numb(nb){
    this->numb = nb;
    strcpy_s(this->str, strlen(st)+1, st);
}

node::node(const node &nodecpy):mcoord(nodecpy.pcoord[0], nodecpy.pcoord[1]){
    this->numb = nodecpy.numb;
    strcpy_s(this->str, strlen(nodecpy.str)+1, nodecpy.str);
}

void node::operator=(const node &ob) { 
    this->numb = ob.numb; 
    strcpy_s(this->str, strlen(ob.str)+1, ob.str); 
    this->pcoord[0] = ob.pcoord[0]; 
    this->pcoord[1] = ob.pcoord[1]; 
}

bool node::operator == (const node &num){
	if (this->numb == num.numb && !(strcmp(this->str, num.str)) &&this->pcoord[0] == num.pcoord[0] && this->pcoord[1] == num.pcoord[1])
        return true;
    return false;
}

std::ostream &operator<<(std::ostream &strm, const node &ob) {
	strm << ob.numb << " ; " << ob.str << " ; " << ob.pcoord[0] << " ; " << ob.pcoord[1];
	return strm;
}

std::istream &operator>>(std::istream &strm, node &ob) {
	strm >> ob.numb >> ob.str >> ob.pcoord[0] >> ob.pcoord[1];
	return strm;
}

void node::writeb(std::ofstream &strm){
	strm.write((char *) &this->numb, sizeof(this->numb));
	strm.write((char *) this->str, sizeof(this->str));
	strm.write((char *) &this->pcoord[0], sizeof(this->pcoord[0]));
	strm.write((char *) &this->pcoord[1], sizeof(this->pcoord[1]));
}

void node::readb(std::ifstream &strm){
	strm.read((char *) &this->numb, sizeof(this->numb));
	strm.read((char *) this->str, sizeof(this->str));
	strm.read((char *) &this->pcoord[0], sizeof(this->pcoord[0]));
	strm.read((char *) &this->pcoord[1], sizeof(this->pcoord[1]));
}